import { ProFormTimePicker } from '@ant-design/pro-components';
import type { ProFormFieldItemProps } from '@ant-design/pro-form/lib/interface';
import type { RangePickerProps } from 'antd/lib/date-picker';

const CommonFormTimeRange: React.FC<ProFormFieldItemProps<RangePickerProps>> = ({
  required,
  rules = [],
  ...props
}) => {
  return (
    <ProFormTimePicker.RangePicker
      {...props}
      rules={
        rules.some((rule) => 'required' in rule)
          ? rules
          : [
              {
                required,
                message: `请选择${props.label}`,
              },
              ...rules,
            ]
      }
    />
  );
};

CommonFormTimeRange.defaultProps = { required: false, placeholder: '' };

export default CommonFormTimeRange;
